

import 'package:flutter/material.dart';
import 'package:yuan_hang_app/res/w_colors.dart';
import 'package:yuan_hang_app/res/w_style.dart';
import 'package:yuan_hang_app/utils/size_utils.dart';
import 'package:yuan_hang_app/widget/w_text.dart';

enum BtnTheme { normal, flat, border }

class WButton extends StatelessWidget {
  final double? width;
  final double height;
  final double corner;
  final String text;
  final double fontSize;
  final Widget? image;
  final Color? color;
  final Color? textColor;
  final Color? endColor;
  final Color? disableColor;
  final Color? disableTextColor;
  final bool enable;
  final BtnTheme theme;
  final bool isBold;
  final Function? onPressedCallBack;

  WButton({
    this.width,
    this.height = 48,
    this.corner = 4,
    this.text = "",
    this.fontSize = 16,
    this.image,
    this.disableColor,
    this.disableTextColor,
    this.color,
    this.textColor,
    this.endColor,
    this.theme = BtnTheme.normal,
    this.isBold = true,
    this.enable = true,
    this.onPressedCallBack,
  });

  @override
  Widget build(BuildContext context) {
    switch (theme) {
      case BtnTheme.normal:
        return TextButton(
          clipBehavior: Clip.hardEdge,
          onPressed: () {
            if (enable) {
              onPressedCallBack?.call;
            }
          },
          child: Container(
              decoration: BoxDecoration(
                  gradient: LinearGradient(colors: [
                enable
                    ? (color ?? Theme.of(context).primaryColor)
                    : (disableColor ?? WColors.CCCCCCC),
                enable
                    ? (endColor ?? color ?? Theme.of(context).primaryColor)
                    : (disableColor ?? WColors.CCCCCCC)
              ])),
              height: height.px,
              width: width,
              child:
                  Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                image != null
                    ? Container(
                        margin: EdgeInsets.only(right: 6.px),
                        child: image,
                      )
                    : const SizedBox(),
                WText(
                  text,
                  style: WStyle.base(
                      size: fontSize.px,
                      isBold: isBold,
                      color: enable
                          ? (textColor ?? Colors.white)
                          : (disableTextColor ?? Colors.white)),
                ),
              ])),
        );
      case BtnTheme.flat:
        return TextButton(
          // padding: EdgeInsets.zero,
          clipBehavior: Clip.hardEdge,
          onPressed: () {
            if (enable) {
              onPressedCallBack?.call;
            }
          },
          // shape: RoundedRectangleBorder(
          //   borderRadius: BorderRadius.circular(corner.px ),
          // ),
          child: Container(
              decoration: BoxDecoration(
                  gradient: LinearGradient(colors: [
                enable
                    ? (color ?? Theme.of(context).primaryColor)
                    : (disableColor ?? WColors.CCCCCCC),
                enable
                    ? (endColor ?? color ?? Theme.of(context).primaryColor)
                    : (disableColor ?? WColors.CCCCCCC)
              ])),
              height: height,
              width: width,
              child:
                  Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                image != null
                    ? Container(
                        margin: EdgeInsets.only(right: 6.px),
                        child: image,
                      )
                    : const SizedBox(),
                WText(
                  text ?? '',
                  style: WStyle.base(
                      size: fontSize.px,
                      isBold: isBold,
                      color: enable
                          ? (textColor ?? Colors.white)
                          : (disableTextColor ?? Colors.white)),
                ),
              ])),
        );
      case BtnTheme.border:
        return TextButton(
          clipBehavior: Clip.hardEdge,
          // shape: RoundedRectangleBorder(
          //     borderRadius: BorderRadius.circular(corner.px),
          //     side: BorderSide(
          //         color: enable
          //             ? (color ?? Theme.of(context).primaryColor)
          //             : WColor.CCCCCCC)),
          onPressed: () {
            if (enable) {
              onPressedCallBack?.call;
            }
          },
          child: SizedBox(
              height: height,
              width: width,
              child:
                  Row(mainAxisAlignment: MainAxisAlignment.center, children: [
                image != null
                    ? Container(
                        margin: EdgeInsets.only(right: 6.px),
                        child: image,
                      )
                    : const SizedBox(),
                WText(
                  text ?? '',
                  style: WStyle.base(
                      size: fontSize.px,
                      isBold: isBold,
                      color: enable
                          ? (textColor ??
                              color ??
                              Theme.of(context).primaryColor)
                          : (disableTextColor ?? WColors.CCCCCCC)),
                ),
              ])),
        );
    }
  }
}
